package com.ep.thirdPlatformProject.mq.listener;


/*
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQTransactionListener;
import org.apache.rocketmq.spring.core.RocketMQLocalTransactionListener;
import org.apache.rocketmq.spring.core.RocketMQLocalTransactionState;
import org.apache.rocketmq.spring.support.RocketMQHeaders;
import org.springframework.messaging.Message;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;


@Slf4j
@RocketMQTransactionListener
public class MQTransactionListener implements RocketMQLocalTransactionListener {
    private static final Map<String, RocketMQLocalTransactionState> STATE_MAP = new HashMap<>();

    */
/**
     * 执行半事务处理
     *
     * @param message 消息
     * @param o       o
     * @return {@link RocketMQLocalTransactionState }
     *//*

    @Override
    public RocketMQLocalTransactionState executeLocalTransaction(Message message, Object o) {
        try {
            String id = Objects.requireNonNull(message.getHeaders().get(RocketMQHeaders.TRANSACTION_ID)).toString();
            String payload = new String((byte[]) message.getPayload());
            log.info("payload:{}", payload);
            STATE_MAP.put(id, RocketMQLocalTransactionState.COMMIT);
            return RocketMQLocalTransactionState.UNKNOWN;
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return RocketMQLocalTransactionState.ROLLBACK;
        }
    }

    */
/**
     * 检查本地事务 (回查消息，确认消息是否收到！)
     *
     * @param message 消息
     * @return {@link RocketMQLocalTransactionState }
     *//*

    @Override
    public RocketMQLocalTransactionState checkLocalTransaction(Message message) {
        String transId = (String) message.getHeaders().get(RocketMQHeaders.TRANSACTION_ID);
        System.out.println("回查消息 -> transId = " + transId + ", state = " + STATE_MAP.get(transId));
        // 如果取到了对应的数据，就提交，否则丢掉这个消息（重试机制）
        return STATE_MAP.getOrDefault(transId, RocketMQLocalTransactionState.ROLLBACK);
    }
}
*/
